//
//  SelectView.m
//  GiftItems
//
//  Created by lanou3g on 15/9/18.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "SelectView.h"
#import "SelectCollectionViewCell.h"
#import "ClassCollectionReusableView.h"

@implementation SelectView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //创建一个布局对象
        UICollectionViewFlowLayout *classcificationCVFlayout = [[UICollectionViewFlowLayout alloc] init];
        //设置集合视图行间距
        classcificationCVFlayout.minimumLineSpacing = 10;
        //设置集合视图每个item之间的间隔
        classcificationCVFlayout.minimumInteritemSpacing = 15;
        //设置集合视图中每个item的大小
        classcificationCVFlayout.itemSize = CGSizeMake(80, 100);
        //设置layer的大小(居上,居左,居下,居右)
        classcificationCVFlayout.sectionInset = UIEdgeInsetsMake(0, 30, 0, 30);
        //设置集合视图的增广视图大小
        classcificationCVFlayout.headerReferenceSize = CGSizeMake(self.bounds.size.width, 50);
        //创建集合视图
        self.ClassificationCV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 114) collectionViewLayout:classcificationCVFlayout];
        //指定集合视图的数据源
        self.ClassificationCV.dataSource = self;
        self.ClassificationCV.delegate = self;
        //注册 集合视图
        [self.ClassificationCV registerClass:[SelectCollectionViewCell class] forCellWithReuseIdentifier:@"MyCell"];
        //注册 增广视图
        [self.ClassificationCV registerClass:[ClassCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyView"];
        [self addSubview:self.ClassificationCV];
    }
    return self;
}

//必须要实现的方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}
//创建cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SelectCollectionViewCell *selectCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
    return selectCell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    ClassCollectionReusableView *classReusableV = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyView" forIndexPath:indexPath];
    return classReusableV;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
